home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / os2 / freetype.zip / testtime.pas < prev    next >
Pascal/Delphi Source File  |  1996-09-07  |  6KB  |  320 lines

  1. program TrueType_Time;
  2.  
  3. uses Crt, Dos, TTDisp, TTTypes, TTCalc, TTTables, Raster;
  4.  
  5. { $DEFINE DEBUG}
  6. { $DEFINE VISUAL}
  7.  
  8. const
  9.   Precis  = 64;
  10.   Precis2 = Precis div 2;
  11.  
  12.   PrecisAux = 1024;
  13.  
  14.   Centre_X : int = 320;
  15.   Centre_Y : int = 225;
  16.  
  17.   Profile_Buff_Size = 64000;
  18.  
  19. var
  20.  
  21.   Font_Buffer : PStorage;
  22.  
  23.   curGlyphContours : PGlyphContours;
  24.  
  25.   num_pts : word;
  26.   num_ctr : word;
  27.  
  28.   glyfArray : word;
  29.  
  30.   epts_ctr : PShortArray;
  31.  
  32.   xCoord : PStorage;
  33.   yCoord : PStorage;
  34.   Flag   : PByteArray;
  35.  
  36.   ymin, ymax, xmax, xmin, xsize : longint;
  37.   res,  resB                    : int;
  38.  
  39.   resR : real;
  40.  
  41.   resX, resY : real;
  42.  
  43.   LastX, LastY : FixedPoint;
  44.  
  45.   numPoints, numContours : int;
  46.  
  47.   curGlyph        : ^TGlyph;
  48.   curGlyphContour : PGlyphContour;
  49.  
  50.   Bit : TRasterBlock;
  51.  
  52.   yCur : integer;
  53.  
  54.   ScXMax, ScYMax,
  55.   CntX, CntY : Integer;
  56.  
  57.   Rotation : int;  (* Angle modulo 1024 *)
  58.  
  59.  
  60. Procedure InitRows;
  61. var
  62.   i: integer;
  63.   P: Pointer;
  64. begin
  65.  
  66.   Bit.rows  := 450;
  67.   Bit.cols  := 80;
  68.   Bit.width := 640;
  69.   Bit.flow  := TTFlowDown;
  70.   Bit.size  := 80*450;
  71.  
  72.   GetMem( Bit.buffer, Bit.size );
  73.   if Bit.buffer = NIL then
  74.    begin
  75.     Writeln('ERREUR:InitRows:Pas assez de mémoire pour le BitMap');
  76.     halt(1);
  77.    end;
  78.  
  79.   GetMem( P, Profile_Buff_Size );
  80.   if P=nil then
  81.    begin
  82.     writeln('ERREUR:InitRows:Pas assez de mémoire pour le buffer profils');
  83.     Halt(2);
  84.    end;
  85.  
  86.   InitRasterizer( Bit, P, Profile_Buff_Size );
  87.  
  88.   FillChar( Bit.Buffer^, Bit.Size, 0 );
  89. end;
  90.  
  91.  
  92. Procedure Clear_Buffer;
  93. begin
  94.   FillChar( Bit.Buffer^, Bit.Size, 0 );
  95. end;
  96.  
  97. Procedure ClearData;
  98. var i: integer;
  99. begin
  100.   FreeMem( XCoord, SizeOf(FixedPoint)*numPoints );
  101.   FreeMem( YCoord, SizeOf(FixedPoint)*numPoints );
  102.  
  103.   FreeMem( Flag, numPoints );
  104. end;
  105.  
  106.  
  107. Function LoadTrueTypeChar( idx : integer ) : boolean;
  108. var
  109.   off    : longint;
  110.   x, y   : Real;
  111.   i, szp : integer;
  112.   j      : word;
  113.   c, ct  : byte;
  114.   Gl     : TGlyph;
  115.   EM     : Word;
  116.   CR, SR : Real;
  117.  
  118. begin
  119.   LoadtrueTypeChar:=FALSE;
  120.   if (idx<0) or (idx>=Num_Glyphs) then exit;
  121.  
  122.   CurGlyph := @Glyphs^[idx];
  123.   Gl       := CurGlyph^;
  124.  
  125.   numPoints        := Gl.numberOfPoints;
  126.   numContours      := Gl.numberOfContours;
  127.   curGlyphContours := Gl.Contours;
  128.  
  129.   GetMem( XCoord, SizeOf(Fixed)*numPoints );
  130.   GetMem( YCoord, SizeOf(Fixed)*numPoints );
  131.   GetMem( Flag, numPoints );
  132.  
  133.   xMin := Gl.xMin;
  134.   xMax := Gl.xMax;
  135.   yMin := Gl.yMin;
  136.   yMax := Gl.yMax;
  137.  
  138.   EM := Font_Header^.UnitsPerEM;
  139.  
  140.   dec( xMax, xMin );
  141.   dec( yMax, yMin );
  142.  
  143.   dec ( res );
  144.   resR := res/EM/2;
  145.  
  146.   xmax := trunc( xmax*resR+0.5 );
  147.   ymax := trunc( ymax*resR+0.5 );
  148.  
  149.   CR := Cos( Rotation*Pi/512 );
  150.   SR := Sin( Rotation*Pi/512 );
  151.  
  152.   for j:=0 to numPoints-1 do
  153.    begin
  154.  
  155.     x := Gl.Points^[j].x * ( res / EM );
  156.     y := Gl.Points^[j].y * ( res / EM );
  157.  
  158.     off := Trunc( Precis*( CR*(x-xmax) + SR*(y-ymax) ) );
  159.     XCoord^[j] := Precis*( Centre_X + off div Precis ) + Precis2;
  160.  
  161.     off := Trunc( Precis*( - SR*(x-xmax) + CR*(y-ymax) ) );
  162.     YCoord^[j] := Precis*( Centre_Y + off div Precis ) + Precis2;
  163.  
  164.     Flag^[j] := Gl.Points^[j].flag;
  165.    end;
  166.  
  167.   inc ( res );
  168.   resR := 1/res;
  169.  
  170.   xsize := ( xmax + 7 ) div 8;
  171.  
  172.   LoadTrueTypeChar:=TRUE;
  173. end;
  174.  
  175.  
  176. function Get_Time : LongInt;
  177. var
  178.   heure,
  179.   min,
  180.   sec,
  181.   cent :
  182. {$IFDEF OS2}
  183.   longint;
  184. {$ELSE}
  185.   word;
  186. {$ENDIF}
  187. begin
  188.   GetTime( heure, min, sec, cent );
  189.   Get_Time := 6000*longint(min) + 100*longint(sec) + cent;
  190. end;
  191.  
  192.  
  193.  
  194.  
  195. function ConvertRaster : boolean;
  196. var
  197.   B : Array[0..128] of Integer;
  198.   i : integer;
  199.   G : TGlyphRecord;
  200. begin
  201.  
  202.   for i := 0 to numContours-1 do
  203.     B[i] := CurGlyphContours^[i].Finish;
  204.  
  205.   G.Outlines  := numContours;
  206.   G.OutStarts := @B;
  207.   G.Points    := numPoints;
  208.   G.XCoord    := XCoord;
  209.   G.YCoord    := YCoord;
  210.   G.Flag      := Flag;
  211.  
  212.   ConvertRaster := RenderGlyph( G, res, res );
  213. end;
  214.  
  215.  
  216.  
  217.  
  218. var i: integer;
  219.     C : Char;
  220.  
  221.     T : longint;
  222.  
  223.     Filename : String;
  224.  
  225.     Fail : Int;
  226.  
  227.  
  228. begin
  229.   GetMem    ( Font_Buffer, 64000 );
  230.   InitBuffer( Font_Buffer^, 64000 );
  231.  
  232.   curGlyphContours:=NIL;
  233.  
  234.   num_pts   :=0;
  235.   num_ctr   :=0;
  236.  
  237.   xCoord  :=NIL;
  238.   yCoord  :=NIL;
  239.   Flag    :=NIL;
  240.  
  241.   for i:=0 to ParamCount do Writeln(ParamStr(i));
  242.  
  243.   If paramCount<>1 then
  244.    begin
  245.     Writeln('Usage : ',paramStr(0),' FontName[.TTF]');
  246.     Halt(1);
  247.    end;
  248.  
  249.   Filename := ParamStr(1);
  250.   if Pos('.',FileName)=0 then FileName:=FileName+'.TTF';
  251.   if not Open_TrueType_File(Filename ) then
  252.    begin
  253.     Writeln('Erreur, le fichier ',ParamStr(1),' n''a pu être ouvert');
  254.     Halt(1);
  255.    end;
  256.  
  257.   res  := 450;
  258.   resB := (res+7) div 8;
  259.  
  260.   Rotation := 0;
  261.  
  262.   Load_TrueType_Tables;
  263.  
  264.   Load_TrueType_MaxProfile;
  265.  
  266.   if Load_TrueType_Glyphs=0 then
  267.    begin
  268.     Writeln('Problème lors du chargement des glyphes');
  269.     Halt(1);
  270.    end;
  271.  
  272.   InitRows;
  273.  
  274.   res  := 850;
  275.   Fail := 0;
  276.  
  277. {$IFDEF VISUAL}
  278.   SetGraphScreen;
  279. {$ENDIF}
  280.  
  281.   T := Get_Time;
  282.  
  283.   for i:=0 to Num_Glyphs-1 do
  284.    begin
  285.     if LoadtrueTypeChar(i) then
  286.      begin
  287.  
  288. {$IFDEF VISUAL}
  289.  
  290.       if ConvertRaster then
  291.  
  292.           Display( Bit.Buffer^, 450, 80 )
  293.       else
  294.         inc(Fail);
  295.  
  296.       Clear_Buffer;
  297. {$ELSE}
  298.       if not ConvertRaster then
  299.         inc(Fail);
  300. {$ENDIF}
  301.       ClearData;
  302.      end;
  303.    end;
  304.  
  305. {$IFDEF VISUAL}
  306.   RestoreScreen;
  307. {$ENDIF}
  308.   Write  (' Temps écoulé : ');
  309.  
  310.   T := Get_Time - T;
  311.   if T < 0 then T := T + 100*60*60;
  312.  
  313.   writeln('Temps : ', T/100:0:2,' s');
  314.   writeln('Echecs: ',Fail );
  315.  
  316.   Close_TrueType_File;
  317.   Readkey;
  318. end.
  319.  
  320.